(() => {
  try {
    const data = {
      palette: [0, 0, 1, 0, 2, 0, 3, 0],
      layers: ["0,0,0;1,1,1;2,2,2"],
    };
    const position = { x: 1, y: 1, z: 1 };

    if (!data || !data.palette || !data.layers) {
      console.error("导入失败：数据格式无效。");
      return;
    }
    //@ts-ignore
    const palette = [];
    for (let i = 0; i < data.palette.length; i += 2) {
      palette.push({ id: data.palette[i], rot: data.palette[i + 1] });
    }

    data.layers.forEach((layerString, offsetY) => {
      if (!layerString) {
        return;
      }
      const blocks = layerString.split(";");
      for (const blockStr of blocks) {
        const [offsetX, offsetZ, paletteIndex] = blockStr
          .split(",")
          .map(Number);
        //@ts-ignore
        const blockType = palette[paletteIndex];
        if (blockType) {
          const worldX = position.x + offsetX;
          const worldY = position.y + offsetY;
          const worldZ = position.z + offsetZ;
          voxels.setVoxel(worldX, worldY, worldZ, blockType.id, blockType.rot);
        }
      }
    });

    console.log(
      `结构已成功放置于 ${position.x},${position.y},${position.z} 渲染需要一定时间，请稍等...`
    );
  } catch (e) {
    console.error("执行命令时发生错误:", e);
  }
})();
